/*
 * demo1.cpp
 *
 *  Created on: 2012-8-20
 *      Author: huangyansheng
 */

#include <iostream>
#include <gtest/gtest.h>

using namespace std;

class Product_7 {
public:
	int getPrice(int id);
};
//根据商品的id，获取商品的价格
int Product_7::getPrice(int id) {
	if (id == 1)
		return 10;
	if (id == 2)
		return 20;
	if (id == 5)
		return 50;
	if (id == 10)
		return 100;
	if (id == 1001)
		return 0;
	if (id > 10000)
		return -1;
	return -1;
}

class Shop {
public:
	int total_7(int id, int number);
};
//计算商品总价，price换成了id，修改为从id获取price
int Shop::total_7(int id, int number) {
	Product_7 p;
	int price = p.getPrice(id);
	if (price < 0)
		return -1;
	else if (number < 0)
		return -1;
	else
		return price * number;
}

//修改我们的测试用例
TEST(total_7,price1) {
	Shop dd;
	EXPECT_EQ(100, dd.total_7(1,10));
	EXPECT_EQ(100, dd.total_7(2,5));
	EXPECT_EQ(100, dd.total_7(5,2));
	EXPECT_EQ(100, dd.total_7(10,1));
}
TEST(total_7,price_zero) {
	Shop dd;
	EXPECT_EQ(0, dd.total_7(1001,10));
	EXPECT_EQ(0, dd.total_7(10,0));
}
TEST(total_7,price_negative) {
	Shop dd;
	EXPECT_EQ(-1, dd.total_7(100001,10));
	EXPECT_EQ(-1, dd.total_7(10,-1));
	EXPECT_EQ(-1, dd.total_7(-10,-1));
}

class ShopTest_7: public ::testing::Test {
public:
	Shop *dd;
	static void SetUpTestCase() {
		cout << "SetUpTestCase" << endl;
	}
	void SetUp() {
		dd = new Shop;
	}
	void TearDown() {
		delete dd;
	}
	static void TearDownTestCase() {
		cout << "TearDownTestCase" << endl;
	}
};
TEST_F(ShopTest_7,price1) {
	EXPECT_EQ(100, dd->total_7(1,10));
	EXPECT_EQ(100, dd->total_7(2,5));
	EXPECT_EQ(100, dd->total_7(5,2));
	EXPECT_EQ(100, dd->total_7(10,1));
}
TEST_F(ShopTest_7,price_zero) {
	EXPECT_EQ(0, dd->total_7(1001,10));
	EXPECT_EQ(0, dd->total_7(10,0));
}
